<template>
  <div class="mod-config">
    <basic-container>
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="所在停车场" prop="parkId">
          <el-select v-model="queryParams.parkId" class="m-2" placeholder="所在停车场">
            <el-option v-for="item in parkName" :key="item.id" :label="item.parkName" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="进出口名称" prop="portName">
          <el-input v-model="queryParams.portName" placeholder="进出口名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-button v-if="permissions.stop_parkingport_add" icon="el-icon-plus" type="primary"
            @click="addOrUpdateHandle()">新增</el-button>
        </el-form-item>
      </el-form>

      <div class="avue-crud">
        <el-table :data="dataList" border v-loading="dataListLoading">
          <el-table-column type="index" header-align="center" align="center" label="序号">
          </el-table-column>
          <el-table-column prop="portName" header-align="center" align="center" label="进出口名称">
          </el-table-column>
          <el-table-column prop="parkName" header-align="center" align="center" label="所在停车场">
          </el-table-column>
          <el-table-column prop="portFunType" header-align="center" align="center" label="使用功能类别">
            <template #="scope">
              <dict-tag :options="dicts.port_fun_type" :value="scope.row.portFunType" />
            </template>
          </el-table-column>
          <el-table-column prop="isMain" header-align="center" align="center" label="是否为主闸机">
            <template #="scope">
              <dict-tag :options="dicts.yes_or_no" :value="scope.row.isMain" />
            </template>
          </el-table-column>
          <el-table-column prop="isOnlyMonthly" header-align="center" align="center" label="是否仅月租">
            <template #="scope">
              <dict-tag :options="dicts.yes_or_no" :value="scope.row.isOnlyMonthly" />
            </template>
          </el-table-column>
          <el-table-column prop="isMastFee" header-align="center" align="center" label="是否收费">
            <template #="scope">
              <dict-tag :options="dicts.yes_or_no" :value="scope.row.isMastFee" />
            </template>
          </el-table-column>
          <el-table-column prop="createTime" header-align="center" align="center" label="创建时间">
          </el-table-column>
          <el-table-column header-align="center" align="center" label="操作">
            <template #="scope">
              <el-button v-if="permissions.stop_parkingport_edit" link type="primary" size="small" icon="el-icon-edit"
                @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
              <el-button v-if="permissions.stop_parkingport_del" link type="primary" size="small" icon="el-icon-delete"
                @click="deleteHandle(scope.row.id)">删除</el-button>
              <el-dropdown @command="handleCommand" trigger="click">
                <span class="el-dropdown-link">
                  <el-icon class="el-icon--right">
                    <arrow-down />
                  </el-icon> 更多
                </span>
                <template #dropdown>
                  <el-dropdown-menu>
                    <el-dropdown-item command="a">出口交费二维码</el-dropdown-item>
                    <el-dropdown-item command="b">无牌车入场二维码</el-dropdown-item>
                    <el-dropdown-item command="c">无牌车出场二维码</el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div class="avue-crud__pagination">
        <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle"
          :current-page="queryParams.current" :page-sizes="[10, 20, 50, 100]" :page-size="queryParams.size"
          :total="totalPage" background layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
      </div>
      <!-- 弹窗, 新增 / 修改 -->
      <table-form v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></table-form>
      <twoCode v-if="CodeVisible" ref="CodeVisible"></twoCode>
    </basic-container>
  </div>
</template>

<script>
import { fetchList, delObj } from '@/api/stop/parkingport'
import TableForm from './parkingport-form.vue'
import twoCode from './twoCode.vue'
import { mapGetters } from 'vuex'
import { fetchListTwo } from '@/api/stop/parking'

export default {
  name: 'Parkingport',
  dicts: ['yes_or_no', 'port_fun_type'],
  data () {
    return {
      queryParams: {
        current: 1,
        size: 10,
      },
      dataForm: {
        key: ''
      },
      dataList: [],
      totalPage: 0,
      dataListLoading: false,
      addOrUpdateVisible: false,
      CodeVisible: false,
      parkName: []
    }
  },
  components: {
    TableForm, twoCode
  },
  created () {
    this.getDataList()
    this.getDataLists()
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  methods: {
    getDataLists () {
      fetchListTwo().then(response => {
        this.parkName = response.data.data
      })
    },
    handleCommand (command) {
      switch (command) {
        case 'a':
          this.CodeVisible = true
          this.$nextTick(() => {
            this.$refs.CodeVisible.init()
          })
          break;
        case 'b':
          this.CodeVisible = true
          this.$nextTick(() => {
            this.$refs.CodeVisible.InInit()
          })
          break;
        case 'c':
          this.CodeVisible = true
          this.$nextTick(() => {
            this.$refs.CodeVisible.OutInit()
          })
          break;
      }
    },
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      fetchList(Object.assign(this.queryParams)).then(response => {
        this.dataList = response.data.data.records
        this.totalPage = response.data.data.total
      })
      this.dataListLoading = false
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    // 删除
    deleteHandle (id) {
      this.$confirm('是否确认删除ID为' + id + '的数据项？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        return delObj(id)
      }).then(data => {
        this.$message.success('删除成功')
        this.getDataList()
      }).catch(() => {
      })
    },
    handleQuery () {
      this.queryParams.current = 1;
      this.getDataList()
    },
    resetQuery () {
      this.queryParams = {
        current: 1,
        size: 10,
      };
      //   this.resetForm("queryForm");
      this.handleQuery();
    }
  }
}
</script>
<style scoped>
.el-dropdown-link {
  color: rgb(128, 128, 241);
  font-size: 12px;
  margin-top: 13%;
  cursor: pointer;
}
</style>
